<template>
  <div>
    <la-dialog
      ref="dialogRef"
      :title="dialogTitle"
      :async="true"
      width="550px"
      @confirm="handleSubmit"
      @cancel="handleClose"
    >
      <el-form
        ref="formRef"
        :model="formData"
        label-width="84px"
        :rules="formRules"
      >
        <el-form-item label="名称">
          <el-input v-model="formData.name" />
        </el-form-item>
        <el-form-item label="标识">
          <el-input v-model="formData.code" />
        </el-form-item>
        <el-form-item label="权重">
          <el-input v-model="formData.weigh" type="number" />
        </el-form-item>
        
        <el-form-item label="备注">
          <el-input type="textarea" v-model="formData.remark" />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="formData.status">
            <el-radio label="normal">正常</el-radio>
            <el-radio label="disabled">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </la-dialog>
  </div>
</template>
<script>
import api from "@/lnk/admin/api";
import laDialog from "@/lnk/components/la-dialog/index.vue";
export default {
  components: {
    laDialog,
  },
  data() {
    return {
      mode: "add",
      formData: {
        name: "",
        weigh: 100,
        status:'normal'
      },
      formRules: {},
    };
  },
  computed: {
    dialogTitle() {
      return this.mode == "add" ? "添加" : "编辑";
    },
  },
  methods: {
    async setFormData(row) {
      const res = await api.role.read({ id: row.id });
      this.formData = res.data;
    },
    open(type = "add") {
      this.mode = type;
      this.$refs.dialogRef.open();
      return this;
    },
    close() {
      this.$emit("close");
    },
    async handleSubmit() {
      if (this.mode == "add") {
        const res = await api.role.create(this.formData);
      } else {
        const res = await api.role.update(this.formData);
      }

      this.close();
      this.$emit("success");
    },
    handleClose() {
      console.log(99);
      this.close();
    },
  },
};
</script>
